import os
import cv2
import pose


# read SYN file
class Stream:
    def __init__(self, syn_root, syn_file):
        self.syn_root = syn_root
        self.file_series = os.listdir(syn_root)
        self.file_series.remove(syn_file)
        self.file_series.sort()
        self.t_series = []
        with open(os.path.join(syn_root, syn_file)) as f:
            for row in f.readlines():
                c = row[row.index("#"):row.index("@")].split(",")
                t = ((int(c[4]) - pose.UTC_ZONE) * 60 + int(c[5])) * 60 + int(c[6]) + int(c[7]) * 1e-3
                self.t_series.append(t)

    def get_image(self, idx):
        img = cv2.imread(os.path.join(self.syn_root, self.file_series[idx]))
        return img, self.t_series[idx]



if __name__ == "__main__":
    SYN_root = "/home/ivan/Datasets/SRTP-DATA/20210112-CoreSixPano/ld-image-cylinder/"
    SYN_file = "ld-image.syn"
    stm = Stream(SYN_root,SYN_file)
    stm.get_image(0)
